namespace mecs {
    /** 系统组，组中可以没有逻辑，只负责调用子系统逻辑 */
    export abstract class BaseSysGroup extends BaseSys {
        /** 子系统列表 */
        subSystems: BaseSys[];
        /** 当前sys组中，是否需要entity，一般不需要，特殊需求，这里在onInit中覆盖，设置其为true */
        protected mGroupNeedEntity: boolean;

        protected mInit() {
            super.mInit();
            this.subSystems = [];
            this.mInitSubSystems()
            this.mOnInit();
        }
        get compTuples() {
            return []
        }

        protected mOnInit() {
            this.mGroupNeedEntity = false;
        }

        abstract mInitSubSystems(): void;

        update(time: number) {
            this.subSystems.forEach(ss => {
                ss.update(time);
            })
        }

        /** 增加此system关注的实体 */
        addEntity(entity: mecs.BaseEntity) {
            if (this.mGroupNeedEntity) {
                super.addEntity(entity);
            }
            this.subSystems.forEach(ss => {
                ss.addEntity(entity);
            })
        }

        /** 删除此system关注的实体 */
        removeEntity(entity: mecs.BaseEntity | number) {
            if (this.mGroupNeedEntity) {
                super.removeEntity(entity);
            }
            this.subSystems.forEach(ss => {
                ss.removeEntity(entity);
            })
        }

        resetData(data: ICacheSys) {
            super.resetData(data);
            if (data.childs) {
                for (let i = 0; i < this.subSystems.length; i++) {
                    this.subSystems[i].resetData(data.childs[this.subSystems[i].sysName])
                }
            }
        }

        cloneData() {
            let d: ICacheSys = super.cloneData();
            d.childs = {};
            for (let i = 0; i < this.subSystems.length; i++) {
                let child = this.subSystems[i];
                d.childs[child.sysName] = child.cloneData();
            }
            return d;
        }

        dispose() {
            if (this.subSystems) {
                for (let i = 0; i < this.subSystems.length; i++) {
                    this.subSystems[i].dispose();
                }
            }
            this.subSystems = null;
            super.dispose()
        }

        protected mUpdateEntity(entity: mecs.BaseEntity, time: number) { }

    }
}